
#include <stdio.h>
#include <stdlib.h>
#include <pic18f6722.h>
#define uint unsigned int
#define uchar unsigned char


uchar Device_Trigger_CheckFire();
uchar Device_Trigger_CheckSafe();
uchar Device_Trigger_CheckDir();
uchar Device_Trigger_CheckAdapter();
void Device_Trigger_Delay();

#define Trigger_fire RD6   //BUTTON A
#define Trigger_safe RD7   //BUTTON B


#define Trigger_Dir  RC1   //BUTTON C

#define Adapter_Det  RD3

//*********************************************************************
/* Check firing trigger Button A
 * return 1 = No firing trigger A
 * return 0 = firing trigger A
 * author: Guichuan.He
 * date: 2016-9-23
*/
//**********************************************************************
uchar Device_Trigger_CheckFire()
{
    if(Trigger_fire == 1)
    {
        return 1;
    }
    else
    {
     // Device_Trigger_Delay();
       if(Trigger_fire == 1)
       {
           return 1;
       }
       else
       {
           return 0;
       }
    }   
}
//*********************************************************************
/* Check Safe trigger Button B
 * return 1 = No firing trigger B 
 * return 0 = firing trigger  B
 * author: Guichuan.He
 * date: 2016-9-23
*/
//**********************************************************************
uchar Device_Trigger_CheckSafe()
{
    if(Trigger_safe == 1)
    {
        return 1;
    }
    else
    {
      Device_Trigger_Delay();
       if(Trigger_safe == 1)
       {
           return 1;
       }
       else
       {
           return 0;
       }
    }   
}
//*********************************************************************
/* Check Direction trigger Button C
 * return 1 = No firing trigger C 
 * return 0 = firing trigger  C
 * author: Guichuan.He
 * date: 2016-9-23
*/
//**********************************************************************
uchar Device_Trigger_CheckDir()
{
    if(Trigger_Dir == 1)
    {
        return 1;
    }
    else
    {
      Device_Trigger_Delay();
       if(Trigger_Dir == 1)
       {
           return 1;
       }
       else
       {
           return 0;
       }
    }   
}
//*********************************************************************
/* Check Adapter detection
 * return 1 = No Connect with adapter
 * return 0 = Connect with adapter
 * author: Guichuan.He
 * date: 2016-9-23
*/
//**********************************************************************
uchar Device_Trigger_CheckAdapter()
{
    if(Adapter_Det == 1)
    {
        return 1;
    }
    else
    {
      Device_Trigger_Delay();
       if(Adapter_Det == 1)
       {
           return 1;
       }
       else
       {
           return 0;
       }
    }   
}

//*********************************************************************
/* trigger Delay
 * author: Guichuan.He
 * date: 2016-9-23
*/
//**********************************************************************
void Device_Trigger_Delay( )
{
    uint i ;
    uint j ;
    for( i=0; i<100; i++)
       for(j=0; j<1; j++);
            
}
